home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / amiga / csrc720j.lzh / mbterm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-08  |  2.6 KB  |  160 lines

  1.  
  2. /*
  3.  *  MBTERM.C - 10/19/87 - Terminal emulators and things.
  4.  */
  5.  
  6. #include "mb.h"
  7. #ifdef MCH_AMIGA
  8. extern char hostport;
  9. extern char tmpstr[];
  10. #endif
  11. char *talkm1, *talkm2, *talkm3, *talkm4;
  12.  
  13. /*
  14.  *  User wants to talk to the console.
  15.  */
  16.  
  17. utalk()
  18. {
  19.   register PORTS *p;
  20.   register short i;
  21.  
  22.   p = port;
  23.   prtx(talkm2);
  24.  
  25.   ioport(cport);
  26.   prtx(talkm4);
  27.  
  28.   for (i = 0; i < 10; i++)
  29.   {
  30.     wait(2);
  31.     if (s_param & s_page) outchar(ctl_g);
  32.     wait(1);
  33.     if (s_param & s_page) outchar(ctl_g);
  34.  
  35.     if (instat())
  36.     {
  37.       cport->fl = NULL;
  38.       if (p->tmode)
  39.       {
  40.    ioport(p);
  41.    cmdtnc(); convtnc();
  42.       }
  43.       term(p);
  44.       ioport(p);
  45.       if (p->tmode)
  46.       {
  47.    cmdtnc();
  48.    trantnc();
  49.       }
  50.       return;
  51.     }
  52.  
  53.     ioport(p);
  54.     if (instat()) return;
  55.     ioport(cport);
  56.   }
  57.   ioport(p); port->msg = talkm3;
  58. }
  59.  
  60. /*
  61.  *  Console used as terminal to tnc.
  62.  */
  63.  
  64. lterm()
  65. {
  66.   register PORTS *m, *s;
  67.  
  68.   m = cport;
  69.  
  70.   if (m->flds is 2)
  71.   if ((m->fl = fopen(m->fld[1], "r")) isnt NULL)
  72.   { fclose(m->fl); m->msg = mexst; return; }
  73.  
  74.   if ((s = findport(m->opt2)) is NULL) { m->msg = mnport; return; }
  75.   if (s is m)                          { m->msg = mcant;  return; }
  76.  
  77.   if (!(s->flags & p_term))
  78.   {
  79.     if (!(s->mode & idle)) { m->msg = minuse; return; }
  80.     ioport(s);
  81.  
  82.     switch(s->dev)
  83.     {
  84. #ifdef MCH_AMIGA
  85.       case p_nulmdm:
  86. #else
  87.       case p_serial:
  88. #endif
  89.    prtx("*** CONNECTED to $O\n");
  90.    break;
  91.  
  92.       default: ;
  93.     }
  94.  
  95.     s->flags setbit p_term;
  96.   }
  97.  
  98.   m->fl = NULL;
  99.   if (m->flds is 2) m->fl = fopen(m->fld[1], "w");
  100. #ifdef MCH_AMIGA
  101.    if(hostport != 'A') sprintf(tmpstr,"talk.on.%c",hostport);
  102.    else strcpy(tmpstr,"talk.on");
  103. /* send some commands to TNC before talking to it */
  104.    if(s->dev == p_tnc)inittnc(tmpstr,0);
  105. #endif
  106.   term(s);
  107. #ifdef MCH_AMIGA
  108.    if(hostport != 'A') sprintf(tmpstr,"talk.off.%c",hostport);
  109.    else strcpy(tmpstr,"talk.off");
  110. /* send some commands to TNC after talking to it */
  111.    if(s->dev == p_tnc)inittnc(tmpstr,0);
  112. #endif
  113.   ioport(m);
  114.   if (m->fl isnt NULL) fclose(m->fl);
  115. }
  116.  
  117. /*
  118.  *  General "do terminal" things.
  119.  */
  120.  
  121. #ifndef MCH_AMIGA
  122. term(s)
  123. PORTS *s;
  124. {
  125.   register char ch;
  126.   register PORTS *m;
  127.   byte ec;
  128.  
  129.   m = cport;
  130.   m->flags clrbit p_give;
  131.   ec = s->ec;
  132.   s->ec = true;
  133.  
  134.   while(true)
  135.   {
  136.     ioport(m);
  137.     if (instat())
  138.     {
  139.       if ((ch = inchar()) is '\r') ch = '\n';
  140.       if (ch is rchar)
  141.       {
  142.    m->flags setbit p_give;
  143.    s->ec = ec;
  144.    return;
  145.       }
  146.       ioport(s); outchar(ch);
  147.       if (m->fl isnt NULL) if (ch isnt cpmeof) putc(ch, m->fl);
  148.     }
  149.  
  150.     ioport(s);
  151.     if (instat())
  152.     {
  153.       if ((ch = inchar()) is '\r') ch = '\n';
  154.       if (m->fl isnt NULL) if (ch isnt cpmeof) putc(ch, m->fl);
  155.     }
  156.   }
  157. }
  158. #endif
  159.  
  160.